package com.gh.controller.platform;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gh.model.user.UserInfo;
import com.gh.result.Result;
import com.gh.service.UserInfoService;
import com.gh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author Eric
 * @Date 2021/6/21 23:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户列表(条件查询带分页)
     * @return
     */
    @PostMapping("{page}/{limit}")
    public Result userList(@PathVariable Long page,
                           @PathVariable Long limit,
                           UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageList =new Page<>(page,limit);
        IPage<UserInfo> pageModel = userInfoService.selectByPage(pageList,userInfoQueryVo);
        return Result.ok(pageModel);
    }
    /**
     * 用户锁定
     */
    @GetMapping("lock/{userId}/{status}")
    public Result lockUser(@PathVariable Long userId,
                           @PathVariable Integer status){
        userInfoService.lockUser(userId,status);
        return Result.ok();
    }
    /**
     * 用户详情
     */
    @GetMapping("show/{userId}")
    public Result showUser(@PathVariable Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }
    /**
     * 认证审批
     */
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,
                           @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
